﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

using Bovril.Core.WPF;

namespace Bovril.Rodney.ViewModel
{
    public class EventNavigator : ViewModelBase
    {
        public EventNavigator()
        {
            RefreshCommand = new RelayCommand<object>(Refresh);

            Refresh(null);
        }

        public ICommand RefreshCommand { get; private set; }

        public Event[] RootNodes { get { return rootNodes_.ToArray(); } }

        private void Refresh(object param)
        {
            rootNodes_.Clear();
            App.ServiceClient.EventHierarchy.Refresh();
            foreach(Bovril.Rodney.Core.IEvent modelEvent in App.ServiceClient.EventHierarchy.RootEvents)
            {
                rootNodes_.Add(new Event(modelEvent));
            }
            NotifyPropertyChanged("RootNodes");
        }

        private ObservableCollection<Event> rootNodes_ = new ObservableCollection<Event>();
    }
}
